package main

import (
	"fmt"
	"strings"
	"time"
)

var now string = ""

const ExpireTime time.Duration = 2

func init() {
	now = "当前时间：" + time.Now().Format("2006-01-02 15:04:05")
}

func main() {
	ch1 := make(chan string)
	ch2 := make(chan string)
	ch3 := make(chan string)

	go func() {
		time.Sleep(ExpireTime * 1 * time.Second)
		ch1 <- "from ch1:" + time.Now().Format("2006-01-02 15:04:05")
	}()

	go func() {
		time.Sleep(ExpireTime * 2 * time.Second)
		ch2 <- "from ch2:" + time.Now().Format("2006-01-02 15:04:05")
	}()

	go func() {
		time.Sleep(ExpireTime * 3 * time.Second)
		ch3 <- "from ch3:" + time.Now().Format("2006-01-02 15:04:05")
	}()

	for i := 0; i < 3; i++ {
		select {
		case msg1 := <-ch1:
			fmt.Println(msg1)
		case msg2 := <-ch2:
			fmt.Println(msg2)
		case msg3 := <-ch3:
			fmt.Println(msg3)
		}
	}

	var stockCode = 123
	var endDate = time.Now().Format("2006-01-02 15:04:05")
	var url = "Code=%d&endDate=%s"
	var targetUrl = fmt.Sprintf(url, stockCode, endDate+"\n")

	fmt.Println(targetUrl, "初始化数据："+now, ExpireTime)

	//多变量定义
	var nickname, age, gender = "Jade", 23, "男"
	fmt.Println(fmt.Sprintf("%s-%d-%s", nickname, age, gender))

	var (
		province = "浙江"
		city     = "杭州"
		region   = "上城"
		village  = "九堡"
		room     = 1604
	)
	fmt.Println(province, city, region, village, room)

	home, work, hobby, fit := "湖北", "搬砖", "Running", "123"
	fmt.Println(strings.Join([]string{home, work, hobby, fit}, "-"))
}
